package cn.openea.perpartner.meily.web.controller;

import cn.openea.perpartner.common.core.web.controller.BaseController;
import cn.openea.perpartner.common.core.web.domain.AjaxResult;
import cn.openea.perpartner.meily.web.entity.BuyingRecord;
import cn.openea.perpartner.meily.web.entity.dto.GroupDto;
import cn.openea.perpartner.meily.web.service.IBuyingRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (BuyingRecord)表控制层
 *
 * @author rains
 * @since 2023-02-09 17:28
 */
@Api(tags = "团购")
@RestController
@RequestMapping("/buying/record")
public class BuyingRecordController extends BaseController {
    @Resource
    private IBuyingRecordService buyingRecordService;

    @ApiOperation("获取商品销量=自定义+实际销量")
    @PostMapping("/totalSales")
    public AjaxResult getTotalSales(@RequestBody GroupDto groupDto){
        long totalSales = this.buyingRecordService.getTotalSales(groupDto);
        return AjaxResult.success("获取商品销量成功！", totalSales);
    }

    @ApiOperation("获取商品实际销售量")
    @PostMapping("/actualSales")
    public AjaxResult getActualSales(@RequestBody GroupDto groupDto){
        long actualSales = this.buyingRecordService.getActualSales(groupDto);
        return AjaxResult.success("获取商品销量成功！", actualSales);
    }

}
